package com.operate.api.operate.dramas.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import com.operate.api.app.balance.dao.AppBalanceDao;
import com.operate.api.app.balance.domain.po.AppBalancePO;
import com.operate.api.app.dramas.dao.VideoCollectDao;
import com.operate.api.app.dramas.dao.VideoLikeDao;
import com.operate.api.app.dramas.dao.VideoPlayDao;
import com.operate.api.app.dramas.domain.po.VideoCollectPO;
import com.operate.api.app.dramas.domain.po.VideoLikePO;
import com.operate.api.app.dramas.domain.po.VideoPlayPO;
import com.operate.api.app.dramas.domain.vo.*;
import com.operate.api.app.info.dao.CompanyDao;
import com.operate.api.app.info.domain.po.CompanyPO;
import com.operate.api.app.info.domain.vo.AppBannerSearchVO;
import com.operate.api.app.search.domain.vo.AppDramaSearchVO;
import com.operate.api.app.search.domain.vo.AppDramaVO;
import com.operate.api.app.user.dao.AppUserDao;
import com.operate.api.app.user.domain.po.AppUserPO;
import com.operate.api.base.Constants;
import com.operate.api.base.Type;
import com.operate.api.operate.dramas.dao.*;
import com.operate.api.operate.dramas.domain.po.*;
import com.operate.api.operate.dramas.domain.vo.*;
import com.operate.api.operate.dramas.service.IDramasService;
import com.operate.api.operate.order.dao.OrderConsumeDao;
import com.operate.api.operate.order.domain.po.OrderConsumePO;
import com.operate.exception.BusinessException;
import com.operate.util.KeyUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;


@Service
@Transactional
@Slf4j
public class DramasServiceImpl implements IDramasService {

    @Autowired
    private VideoDao videoDao;
    @Autowired
    private DramasScheduleDao dramasScheduleDao;
    @Autowired
    private DramasDao dramasDao;
    @Autowired
    private VideoCollectDao videoCollectDao;
    @Autowired
    private VideoLikeDao videoLikeDao;
    @Autowired
    private VideoPlayDao videoPlayDao;
    @Autowired
    private DramasOtherDao otherDao;
    @Autowired
    private AppUserDao userDao;
    @Autowired
    private OrderConsumeDao consumeDao;
    @Autowired
    private AppBalanceDao  balanceDao;
    @Autowired
    private CompanyDao companyDao;
    @Autowired
    private CompanyFlowLogDao flowLogDao;


    @Override
    public List<DramasVO> getList(DramasSearchVO searchVO) {
        List<DramasVO> list= dramasDao.getList(searchVO);
        if(list!=null&&list.size()>0){
            for (DramasVO dramasVO:list){
                if(StringUtils.isNotBlank(dramasVO.getDramaUrl())){
                    dramasVO.setDramaUrl(KeyUtil.encryptFromString(dramasVO.getDramaUrl()));
                }
            }
        }
        return list;
    }

    @Override
    public List<VideoVO> getVideoList(VideoSearchVO searchVO) {
        List<VideoVO> list=videoDao.getList(searchVO);
        if(list!=null&&list.size()>0){
            for (VideoVO videoVO:list){
                if(StringUtils.isNotBlank(videoVO.getVideoOldUrl())){
                    videoVO.setVideoOldUrl(KeyUtil.encryptFromString(videoVO.getVideoOldUrl()));
                }
                if(StringUtils.isNotBlank(videoVO.getVideoUrl())){
                    videoVO.setVideoUrl(KeyUtil.encryptFromString(videoVO.getVideoUrl()));
                }
            }
        }
        return list;
    }

    @Autowired
    private AppUserDao appUserDao;

    @Override
    public List<AppVideoVO> getRandomVideoList(AppRandomVideoSearchVO searchVO) {
        Boolean isYoung=false;
        if(StpUtil.isLogin()){
            searchVO.setUserId(StpUtil.getLoginId().toString());
            searchVO.setDeviceId("");

            AppUserPO appUserPO=appUserDao.selectByPrimaryKey(StpUtil.getLoginId());
            if(appUserPO.getIsYoung()==1){
                isYoung=true;
            }
        }
        String dramaId=dramasDao.getRandomOneId(searchVO);
        if(StringUtils.isBlank(dramaId)){
            if(isYoung){
                return new ArrayList<>();
            }
            searchVO.setCompanyId("");
            dramaId=dramasDao.getRandomOneId(searchVO);
        }
        if(StringUtils.isBlank(dramaId)){
          return  new ArrayList<>();
        }
        AppVideoSearchVO appVideoSearchVO=new AppVideoSearchVO();
        appVideoSearchVO.setDramaId(dramaId);
        return getAppVideoList(appVideoSearchVO);
    }




    @Override
    public List<AppVideoVO> getAppVideoList(AppVideoSearchVO searchVO) {
        if(StpUtil.isLogin()){
            searchVO.setUserId(StpUtil.getLoginId().toString());
        }
        List<AppVideoVO> list= videoDao.getAppVideoList(searchVO);
        for (AppVideoVO appVideoVO :list){
                if(StpUtil.isLogin()){
                    appVideoVO.setIsLike(2);
                    AppVideoLikeVO appVideoLikeVO=new AppVideoLikeVO();
                    appVideoLikeVO.setVideoId(appVideoVO.getId());
                    if(checkLikeVideo(appVideoLikeVO)){
                        appVideoVO.setIsLike(1);
                    }
                    //如果价格0 则隐藏Url
                    if(appVideoVO.getVideoPrice()>BigDecimal.ZERO.intValue()){
                        appVideoVO.setVideoUrl("");
                    }
                }
                if(StringUtils.isNotBlank(appVideoVO.getVideoUrl())){
                    appVideoVO.setVideoUrl(KeyUtil.encryptFromString(appVideoVO.getVideoUrl()));
                }
        }
        return list;
    }



    @Override
    public AppVideoVO getAppVideoOne(String id) {
        AppVideoVO appVideoVO= videoDao.getAppVideoOne(id,StpUtil.getLoginId().toString());
        if(appVideoVO!=null&&StringUtils.isNotBlank(appVideoVO.getVideoUrl())){
            appVideoVO.setVideoUrl(KeyUtil.encryptFromString(appVideoVO.getVideoUrl()));
        }
        return appVideoVO;
    }




    @Override
    public void cancelPlays() {
        Example example = new Example(VideoPlayPO.class);
        example.and().andEqualTo("userId", StpUtil.getLoginId());
        VideoPlayPO videoPlayPO=new VideoPlayPO();
        videoPlayPO.setDelFlag(true);
        videoPlayPO.preUpdate();
        videoPlayDao.updateByExample(videoPlayPO,example);

    }

    @Override
    public List<AppVideoPlayLogVO> getAppPlayList(AppVideoPlayLogSearchVO searchVO) {
        searchVO.setUserId(StpUtil.getLoginId().toString());
        return videoPlayDao.getAppPlayList(searchVO);
    }


    @Override
    public List<AppVideoPlayLogVO> getAppPlayDramaList(AppVideoPlayLogSearchVO searchVO) {
        searchVO.setUserId(StpUtil.getLoginId().toString());
        return videoPlayDao.getAppPlayDramaList(searchVO);
    }


    //收藏剧目
    @Override
    public void addCollect(AppCollectVO vo) {
        DramasPO dramasPO=dramasDao.selectByPrimaryKey(vo.getDramaId());
        if(dramasPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"剧目信息未找到");
        }
        if(checkCollect(vo)){
            throw new BusinessException(Type.FAIL.getCode(),"剧目已经被收藏过");
        }
        //更新追剧日志表
        VideoCollectPO videoCollectPO=new VideoCollectPO();
        videoCollectPO.setDramaId(vo.getDramaId());
        videoCollectPO.setUserId(StpUtil.getLoginId().toString());
        videoCollectPO.preInsert();
        videoCollectDao.insertSelective(videoCollectPO);
        //更新剧目统计表
        Example example = new Example(DramasOtherPO.class);
        example.and().andEqualTo("dramaId",vo.getDramaId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(example);
        otherPO.setCollectNum(new BigDecimal(otherPO.getCollectNum()).add(BigDecimal.ONE).longValue());
        otherDao.updateByPrimaryKeySelective(otherPO);

    }

    @Override
    public void cancelCollect(AppCollectVO vo) {
        DramasPO dramasPO=dramasDao.selectByPrimaryKey(vo.getDramaId());
        if(dramasPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"剧目信息未找到");
        }
        Example example = new Example(VideoCollectPO.class);
        example.and().andEqualTo("dramaId",vo.getDramaId())
                .andEqualTo("userId", StpUtil.getLoginId());
        VideoCollectPO videoCollectPO=videoCollectDao.selectOneByExample(example);
        if(videoCollectPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"剧目未被收藏");
        }
        //更新追剧日志表
        videoCollectDao.deleteByPrimaryKey(videoCollectPO.getId());
        //更新剧目统计表
        Example otherExample = new Example(DramasOtherPO.class);
        otherExample.and().andEqualTo("dramaId",vo.getDramaId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(otherExample);
        otherPO.setCollectNum(new BigDecimal(otherPO.getCollectNum()).subtract(BigDecimal.ONE).longValue());
        otherDao.updateByPrimaryKeySelective(otherPO);
    }



    //检查剧目是否被收藏
    @Override
    public Boolean checkCollect(AppCollectVO vo) {
        Example example = new Example(VideoCollectPO.class);
        example.and().andEqualTo("dramaId",vo.getDramaId())
                .andEqualTo("userId", StpUtil.getLoginId());
        VideoCollectPO videoCollectPO=videoCollectDao.selectOneByExample(example);
        if(videoCollectPO==null){
            return false;
        }
        return true;
    }

    @Override
    public Boolean checkLikeVideo(AppVideoLikeVO vo) {
        Example example = new Example(VideoLikePO.class);
        example.and().andEqualTo("videoId",vo.getVideoId())
                .andEqualTo("userId", StpUtil.getLoginId());
        VideoLikePO videoLikePO=videoLikeDao.selectOneByExample(example);
        if(videoLikePO==null){
            return false;
        }
        return true;
    }

    @Override
    public void cancelLikeVideo(AppVideoLikeVO vo) {
        VideoPO videoPO=videoDao.selectByPrimaryKey(vo.getVideoId());
        if(videoPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"视频信息未找到");
        }
        Example example = new Example(VideoLikePO.class);
        example.and().andEqualTo("videoId",vo.getVideoId())
                .andEqualTo("userId", StpUtil.getLoginId());
        VideoLikePO videoLikePO=videoLikeDao.selectOneByExample(example);
        if(videoLikePO==null){
            throw new BusinessException(Type.FAIL.getCode(),"视频未被收藏");
        }
        //更新视频日志表
        videoLikeDao.deleteByPrimaryKey(videoLikePO.getId());
        //更新视频统计表
        videoPO.setVideoLike(new BigDecimal(videoPO.getVideoLike()).subtract(BigDecimal.ONE).longValue());
        videoPO.preUpdate();
        videoDao.updateByPrimaryKeySelective(videoPO);
        //更新剧目统计表
        Example otherExample = new Example(DramasOtherPO.class);
        otherExample.and().andEqualTo("dramaId",videoPO.getDramaId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(otherExample);
        otherPO.setLikeNum(new BigDecimal(otherPO.getLikeNum()).subtract(BigDecimal.ONE).longValue());
        otherDao.updateByPrimaryKeySelective(otherPO);
    }


    //点赞视频
    @Override
    public void likeVideo(AppVideoLikeVO vo) {
        VideoPO videoPO=videoDao.selectByPrimaryKey(vo.getVideoId());
        if(videoPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"视频信息未找到");
        }
        //更新追剧日志表
        VideoLikePO videoLikePO=new VideoLikePO();
        if(StpUtil.isLogin()){
            if(checkLikeVideo(vo)){
                throw new BusinessException(Type.FAIL.getCode(),"视频已经被点赞过");
            }
            videoLikePO.setUserId(StpUtil.getLoginId().toString());
        }
        videoLikePO.setDramaId(videoPO.getDramaId());
        videoLikePO.setVideoId(vo.getVideoId());
        videoLikePO.preInsert();
        videoLikeDao.insertSelective(videoLikePO);
        videoPO.setVideoLike(new BigDecimal(videoPO.getVideoLike()).add(BigDecimal.ONE).longValue());
        videoPO.preUpdate();
        videoDao.updateByPrimaryKeySelective(videoPO);
        //更新剧目统计表
        Example example = new Example(DramasOtherPO.class);
        example.and().andEqualTo("dramaId",videoPO.getDramaId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(example);
        otherPO.setLikeNum(new BigDecimal(otherPO.getLikeNum()).add(BigDecimal.ONE).longValue());
        otherDao.updateByPrimaryKeySelective(otherPO);
    }


    @Override
    public void playDrama(AppDramasPlayVO vo) {
        DramasPO dramasPO= dramasDao.selectByPrimaryKey(vo.getDramaId());
        VideoPlayPO videoPlayPO=new VideoPlayPO();
        videoPlayPO.setDeviceSign(vo.getDeviceId());
        videoPlayPO.setDramaId(dramasPO.getId());
        if(StpUtil.isLogin()){
            videoPlayPO.setUserId(StpUtil.getLoginId().toString());
        }
        videoPlayPO.preInsert();
        videoPlayDao.insertSelective(videoPlayPO);
        Example example = new Example(DramasOtherPO.class);
        example.and().andEqualTo("dramaId",dramasPO.getId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(example);
        otherPO.setPlayNum(new BigDecimal(otherPO.getPlayNum()).add(BigDecimal.ONE).longValue());
        otherDao.updateByPrimaryKeySelective(otherPO);
        if(dramasPO.getDramaRate().compareTo(BigDecimal.ZERO)>0){
            CompanyPO companyPO= companyDao.selectByPrimaryKey(dramasPO.getCompanyId());
            BigDecimal liuNum=new BigDecimal(vo.getDuration()).divide(new BigDecimal("1000")).multiply(dramasPO.getDramaRate().divide(new BigDecimal("8"),2, RoundingMode.DOWN));
            companyPO.setFlowNum(new BigDecimal(companyPO.getFlowNum()).subtract(liuNum).toString());
            companyDao.updateByPrimaryKeySelective(companyPO);
            CompanyFlowLogPO flowLogPO=new CompanyFlowLogPO();
            flowLogPO.setCompanyId(companyPO.getId());
            flowLogPO.setDramasId(dramasPO.getId());
            flowLogPO.setFlowState(3);
            flowLogPO.setFlowNum(liuNum.toString());
            flowLogPO.preInsert();
            flowLogDao.insertSelective(flowLogPO);
        }

    }

    @Override
    public Integer getLikeNum() {
        Example example=new Example(VideoLikePO.class);
        example.and().andEqualTo("userId",StpUtil.getLoginId());
        return  videoLikeDao.selectCountByExample(example);
    }

    @Override
    public Integer getPlayNum() {
        Example example=new Example(VideoPlayPO.class);
        example.and().andEqualTo("userId",StpUtil.getLoginId());
        return  videoPlayDao.selectCountByExample(example);
    }

    @Override
    public Integer getCollectNum() {
        Example example=new Example(VideoCollectPO.class);
        example.and().andEqualTo("userId",StpUtil.getLoginId());
        return  videoCollectDao.selectCountByExample(example);
    }

    @Override
    public List<AppVideoPlayLogVO> getAppLikeList(AppVideoPlayLogSearchVO searchVO) {
        searchVO.setUserId(StpUtil.getLoginId().toString());
        return videoLikeDao.getAppLikeList(searchVO);
    }

    @Override
    public List<DramaCompanyVO> getCollectList(DramaCollectSearchVO searchVO) {
        searchVO.setUserId(StpUtil.getLoginId().toString());
        return dramasDao.getCollectList(searchVO);
    }

    @Override
    public Integer geDramasCollectNum(String id) {
        Example example=new Example(VideoCollectPO.class);
        example.and().andEqualTo("dramaId",id);
        return  videoCollectDao.selectCountByExample(example);
    }


    //播放视频
    @Override
    public void playVideo(AppVideoPlayVO vo) {
        VideoPO videoPO=videoDao.selectByPrimaryKey(vo.getVideoId());
        if(videoPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"视频信息未找到");
        }

        VideoPlayPO videoPlayPO=new VideoPlayPO();
        videoPlayPO.setDeviceSign(vo.getDeviceId());
        videoPlayPO.setDramaId(videoPO.getDramaId());
        videoPlayPO.setVideoId(videoPO.getId());
        videoPlayPO.preInsert();
        if(StpUtil.isLogin()){
            videoPlayPO.setUserId(StpUtil.getLoginId().toString());
            Example playCountExample=new Example(VideoPlayPO.class);
            playCountExample.and().andEqualTo("videoId",vo.getVideoId())
                    .andEqualTo("userId",videoPlayPO.getUserId()).andEqualTo("deviceSign",vo.getDeviceId())
                    .andEqualTo("deviceSign",videoPlayPO.getDeviceSign())
                    .andBetween("createDate",  DateUtil.beginOfDay(new Date()).toString(),DateUtil.endOfDay(new Date()).toString());
            Integer countUser=videoPlayDao.selectCountByExample(playCountExample);
            if(countUser<1){
                videoPlayDao.insertSelective(videoPlayPO);
             }
        }else{
            videoPlayDao.insertSelective(videoPlayPO);
        }
        Example example = new Example(DramasOtherPO.class);
        example.and().andEqualTo("dramaId",videoPO.getDramaId());
        DramasOtherPO otherPO=otherDao.selectOneByExample(example);
        otherPO.setPlayNum(new BigDecimal(otherPO.getPlayNum()).add(BigDecimal.ONE).longValue());
        Example playExample = new Example(VideoPlayPO.class);
        playExample.and().andEqualTo("deviceSign",vo.getDeviceId()).andEqualTo("dramaId",videoPlayPO.getDramaId());
        Integer count=videoPlayDao.selectCountByExample(playExample);
        if(count==1){
            otherPO.setSeeNum(new BigDecimal(otherPO.getSeeNum()).add(BigDecimal.ONE).longValue());
        }
        otherDao.updateByPrimaryKeySelective(otherPO);
        //流量（kb）=观看视频时长（s）*当前视频码率（kbps）/8
        if(videoPO.getVideoRate().compareTo(BigDecimal.ZERO)>0){
            CompanyPO companyPO= companyDao.selectByPrimaryKey(videoPO.getCompanyId());
            BigDecimal liuNum=new BigDecimal(vo.getDuration()).divide(new BigDecimal("1000")).multiply(videoPO.getVideoRate().divide(new BigDecimal("8"),2, RoundingMode.DOWN));
            companyPO.setFlowNum(new BigDecimal(companyPO.getFlowNum()).subtract(liuNum).toString());
            companyDao.updateByPrimaryKeySelective(companyPO);
            CompanyFlowLogPO flowLogPO=new CompanyFlowLogPO();
            flowLogPO.setCompanyId(companyPO.getId());
            flowLogPO.setVideoId(videoPO.getId());
            flowLogPO.setDramasId(videoPO.getDramaId());
            flowLogPO.setFlowState(3);
            flowLogPO.setFlowNum(liuNum.toString());
            flowLogPO.preInsert();
            flowLogDao.insertSelective(flowLogPO);
        }
    }

    //解锁视频
    @Override
    public void payVideo(AppVideoConsumeVO vo) {
        VideoPO videoPO=videoDao.selectByPrimaryKey(vo.getVideoId());
        if(videoPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"视频信息未找到!");
        }
        if(videoPO.getVideoPrice().compareTo(BigDecimal.ZERO)!=1){
            throw new BusinessException(Type.FAIL.getCode(),"当前视频不需要解锁！");
        }
        AppUserPO appUserPO=userDao.selectByPrimaryKey(StpUtil.getLoginId().toString());
        if(appUserPO==null){
            throw new BusinessException(Type.FAIL.getCode(),"当前用户不存在!");
        }
        Example example = new Example(OrderConsumePO.class);
        example.and().andEqualTo("userId",appUserPO.getId()).andEqualTo("videoId",videoPO.getId()).andEqualTo("dramaId",videoPO.getDramaId());
        Integer count=consumeDao.selectCountByExample(example);
        if(count>0){
            throw new BusinessException(Type.FAIL.getCode(),"已经解锁过当前视频！");
        }
        if(new BigDecimal(appUserPO.getUserBalance()).compareTo(videoPO.getVideoPrice())==-1){
            throw new BusinessException(Type.FAIL.getCode(),"余额不足！");
        }
        appUserPO.setUserBalance(new BigDecimal(appUserPO.getUserBalance()).subtract(videoPO.getVideoPrice()).toBigInteger());
        appUserPO.preUpdate();
        userDao.updateByPrimaryKeySelective(appUserPO);
        //更新商户余额
        CompanyPO companyPO=companyDao.selectByPrimaryKey(videoPO.getCompanyId());
        companyPO.setCompanyMoney(companyPO.getCompanyMoney().add(videoPO.getVideoPrice()));
        companyDao.updateByPrimaryKeySelective(companyPO);
        //添加消费订单
        OrderConsumePO consumePO=new OrderConsumePO();
        consumePO.setCompanyId(videoPO.getCompanyId());
        consumePO.setDramaId(videoPO.getDramaId());
        consumePO.setUserId(appUserPO.getId());
        consumePO.setOrderPrice(videoPO.getVideoPrice().longValue());
        consumePO.setVideoId(videoPO.getId());
        consumePO.preInsert();
        consumeDao.insertSelective(consumePO);
        //添加余额变化日志
        AppBalancePO appBalancePO=new AppBalancePO();
        appBalancePO.setUserId(consumePO.getUserId());
        appBalancePO.setOrderDesc("解锁"+videoPO.getVideoName());
        appBalancePO.setOrderId(consumePO.getId());
        appBalancePO.setOrderNum(videoPO.getVideoPrice().negate());
        appBalancePO.setOrderType(2);
        appBalancePO.preInsert();
        appBalancePO.setCreateDate(consumePO.getCreateDate());
        appBalancePO.setUpdateDate(consumePO.getUpdateDate());
        balanceDao.insertSelective(appBalancePO);
    }

    @Override
    public void updateLines(DramasStateVO vo) {
        DramasPO dramasPO=dramasDao.selectByPrimaryKey(vo.getId());
        if(dramasPO==null){
            throw new BusinessException(Type.NOT_FOUND_ERROR);
        }
        dramasPO.setDramaState(vo.getDramaState());
        dramasPO.preUpdate();
        int i = dramasDao.updateByPrimaryKeySelective(dramasPO);
        if (i == Constants.SQL_RETURN_SUCCESS) {
            throw new BusinessException(Type.FAIL);
        }
        DramasSchedulePO sysDramasSchedulePO=new DramasSchedulePO();
        if(vo.getDramaState()==8){
            sysDramasSchedulePO.setDramaId(dramasPO.getId());
            sysDramasSchedulePO.setLogType(5);
            sysDramasSchedulePO.setLogState(3);
            sysDramasSchedulePO.setLogTitle("下线");
            sysDramasSchedulePO.setLogDesc("下线原因："+vo.getStateDesc());
        }else{
            sysDramasSchedulePO.setDramaId(dramasPO.getId());
            sysDramasSchedulePO.setLogType(5);
            sysDramasSchedulePO.setLogState(3);
            sysDramasSchedulePO.setLogTitle("重新上线");
        }
        sysDramasSchedulePO.preInsert();
        int j = dramasScheduleDao.insertSelective(sysDramasSchedulePO);
        if (j == Constants.SQL_RETURN_SUCCESS) {
            throw new BusinessException(Type.FAIL);
        }
    }

    @Override
    public List<DramaTrailersVO> getTrailersList(DramaTrailersSearchVO searchVO) {
        List<DramaTrailersVO> list=dramasDao.getTrailersList(searchVO);
        for (DramaTrailersVO dramaTrailersVO :list){
            if(StpUtil.isLogin()){
                dramaTrailersVO.setIsCollect(2);
                AppCollectVO appCollectVO=new AppCollectVO();
                appCollectVO.setDramaId(dramaTrailersVO.getId());
                if(checkCollect(appCollectVO)){
                    dramaTrailersVO.setIsCollect(1);
                }

            }
            if(StringUtils.isNotBlank(dramaTrailersVO.getDramaUrl())){
                dramaTrailersVO.setDramaUrl(KeyUtil.encryptFromString(dramaTrailersVO.getDramaUrl()));
            }
        }
        return list;
    }


    @Override
    public DramaTrailersVO getTrailersDesc(String id) {
        DramaTrailersVO vo =dramasDao.getTrailersDesc(id);
        if(vo!=null){
            if(StpUtil.isLogin()){
                vo.setIsCollect(2);
                AppCollectVO appCollectVO=new AppCollectVO();
                appCollectVO.setDramaId(vo.getId());
                if(checkCollect(appCollectVO)){
                    vo.setIsCollect(1);
                }
            }
            if(StringUtils.isNotBlank(vo.getDramaUrl())){
                vo.setDramaUrl(KeyUtil.encryptFromString(vo.getDramaUrl()));
            }
        }
        return vo;
    }


    @Override
    public List<DramaCompanyVO> getCompanyDramas(DramaCompanySearchVO searchVO) {
        return dramasDao.getCompanyDramas(searchVO);
    }

    @Override
    public List<AppDramaVO> getAppDramaList(AppDramaSearchVO searchVO) {
        return dramasDao.getAppDramaList(searchVO);
    }

}